package com.hongning.railway.ui.main.fragments.home.itemviewmodel;

import android.databinding.ObservableField;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;

import com.hongning.railway.R;
import com.hongning.railway.entity.resbean.ResNewsBean;
import com.hongning.railway.ui.categorylistnews.NewDetailFragment;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class NewItemViewModel extends ItemViewModel<BaseViewModel> {
    public ObservableField<ResNewsBean> news= new ObservableField<>();
    public Drawable drawableImg;


    public BindingCommand newsClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putParcelable(NewDetailFragment.NEWS_INFO,news.get());
            viewModel.startContainerActivity(NewDetailFragment.class.getCanonicalName(),bundle);
        }
    });
    public NewItemViewModel(@NonNull BaseViewModel viewModel,ResNewsBean newsEntity) {
        super(viewModel);
        news.set(newsEntity);
        drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), R.mipmap.icon_app_default);
    }
}

